package com.kevin.iterator.impl;

import com.kevin.iterator.Iterator;

import java.util.List;

/**
 *
 * 具体迭代器
 *
 * @author kevin
 * @date 2025/8/12
 */
public class ConcreteIterator implements Iterator {

    private List<Object> list = null;

    private int index = -1;

    public ConcreteIterator(List<Object> list) {
        this.list = list;
    }

    @Override
    public Object first() {
        return list.indexOf(0);
    }

    @Override
    public Object next() {
        if(hasNext()){
            return list.get(++index);
        }
        return null;
    }

    @Override
    public boolean hasNext() {
        if (index < list.size() - 1){
            return true;
        }
        return false;
    }
}
